<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
	<% String path=request.getContextPath(); String basePath=request.getScheme() + "://" + request.getServerName() + ":"
		+ request.getServerPort() + path + "/" ; %>

		<!DOCTYPE html>
		<html>

		<head>
			<base href="<%=basePath%>">

			<title></title>

			<meta http-equiv="pragma" content="no-cache">
			<meta http-equiv="cache-control" content="no-cache">
			<meta http-equiv="expires" content="0">
			<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
			<meta http-equiv="description" content="This is my page">
			<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

		</head>

		<body>
			<%@ include file="/WEB-INF/jsp/common/header.jsp" %>
				<%@ include file="/WEB-INF/jsp/common/loadDiv.jsp" %>

					<script type="text/javascript">
						$(function () {
							$('#startTime').datebox('setValue', getBeforeCurrentDate90Days());
							$('#endTime').datebox('setValue', getNowFormatDate());
							bindgrid();
						});
					</script>
					<script type="text/javascript">
						var selectedFileList = [];//已选文件列表
						var succsessCount = 0;//上传成功文件个数
						var errorCount = 0;//上传失败文件个数
						/************文件处理部分*************/


						/**
						 *文件框改变事件
						 */
						function changeFile() {
							var files = $("#uploadpicker").prop("files");
							$
								.each(
									files,
									function (index, item) {
										let choiseFile = $("#checkfileList>li");
										if (choiseFile.length > 0) {//文件去重
											let count = 0;
											$.each(choiseFile, function (index1, item1) {
												if (item.name == item1.innerText) {
													count++;
												}
											});
											if (count == 0) {
												if (checkFileLength(item.size)) {
													if (item.name.includes('#') || item.name.includes('/') || item.name.includes('&') || item.name.includes('\\') || item.name.includes(' ')) {
														alert('文件名不能包含&、斜杠、反斜杠、空格等特殊字符！');
														return;
													}
													$("#checkfileList")
														.append(
															"<li class=\"fileinfo\">"
															+ item.name
															+ "<a style=\"display: none; color: red; margin-left: 10px;\" href=\"javascript:void(0)\" onclick=\"RemoveFile(this,'"
															+ item.name
															+ "')\">删除</a>"
															+ "</li>");
													selectedFileList.push(item);
													AddMoushover();
												}
											}
										} else {
											if (checkFileLength(item.size)) {
												if (item.name.includes('#') || item.name.includes('/') || item.name.includes('&') || item.name.includes('\\') || item.name.includes(' ')) {
													alert('文件名不能包含&、斜杠、反斜杠、空格等特殊字符！');
													return;
												}
												$("#checkfileList")
													.append(
														"<li class=\"fileinfo\">"
														+ item.name
														+ "<a style=\"display: none; color: red; margin-left: 10px;\" href=\"javascript:void(0)\" onclick=\"RemoveFile(this,'"
														+ item.name
														+ "')\">删除</a>"
														+ "</li>");
												selectedFileList.push(item);
												AddMoushover();
											}
										}
									});
						}

						/**
						 *    判断文件是否超过限制大小
						 * @param fileLen
						 * @returns {boolean}
						 */
						function checkFileLength(fileLen) {
							if (fileLen > 102400000) {
								$.messager.alert("提示", "上传文件大小不能超过100M", "error");
								return false;
							}
							return true;
						}

						/**
						 * //添加鼠标经过事件，鼠标划过时显示“删除”
						 * @constructor
						 */
						function AddMoushover() {
							$(".fileinfo").hover(function () {
								$(this).find("a").last().css("display", "");
							}, function () {
								$(this).find("a").last().css("display", "none");
							});
						}

						/**
						 *  移除已选择的文件
						 */

						function RemoveFile(obj, fileId) {
							$.messager.confirm("提示", "确认删除当前文件?", function (e) {
								if (e) {
									let index = $("#checkfileList>li").index($(obj).parent());
									selectedFileList.splice(index, 1);
									$(obj).parent().remove();

									$.ajax({
										type: "post",
										url: 'file/deleteFile?fileId=' + fileId,
										success: function (data) {
											$.messager.alert('消息', data);
										},
										error: function (XMLHttpRequest, textStatus,
											errorThrown) {
											$.messager.alert('消息', errorThrown);
										}
									});

								}
							});
						}

						/**
						 * 取得该条数据所属的文件列表
						 * @param row
						 */
						function getFileList(id) {
							$.ajax({
								type: "post",
								url: "file/getFileList",
								data: {
									fileTable: "con_visa",
									fileRow: id
								},
								success: function (data) {
									const dataArray = eval(data);
									initFile(dataArray);
								},
								error: function (XMLHttpRequest, textStatus, errorThrown) {
									$.messager.alert('消息', errorThrown);
								}
							});
						}

						/**
						 * 初始化该条数据的文件列表
						 * @param dataArray
						 */
						function initFile(dataArray) {
							$("#checkfileList").empty();
							// 			sselectedFileNameList = [];
							selectedFileList = [];
							dataArray
								.forEach(function (e, i, a) {
									$("#checkfileList")
										.append(
											"<li class=\"fileinfo\">"
											+ "<a style=\" color: blue; margin-left: 30px;\" href=\"javascript:void(0)\" onclick=\"downloadFile('"
											+ e.FILE_NAME
											+ "','"
											+ e.FILE_ID
											+ "')\">"
											+ e.FILE_NAME
											+ "</a>"
											+ "<a style=\"display: none; color: red; margin-left: 30px;\" href=\"javascript:void(0)\" onclick=\"RemoveFile(this,'"
											+ e.FILE_ID + "')\">删除</a>"
											+ "</li>");
									// 						sselectedFileNameList.push(e.FILE_NAME);
									AddMoushover();
								});
						}

						// 文件下载
						function downloadFile(fileName, fileRow) {
							let url = 'api/file/download?id=' + fileRow
							let xhr = new XMLHttpRequest()
							xhr.open('GET', url, true)
							xhr.setRequestHeader('token', localStorage.getItem('tokenSupply'));
							xhr.setRequestHeader('userType', localStorage.getItem('userType'));
							xhr.responseType = 'blob'
							xhr.onload = function (data) {
								if (this.status == 200) {
									let blob = this.response
									let reader = new FileReader()
									reader.readAsDataURL(blob)
									reader.onload = function (e) {
										let a = document.createElement('a')
										a.download = fileName
										a.href = e.target.result
										$('body').append(a)
										a.click()
										$(a).remove()
									}
								} else {

								}
							}
							xhr.send()
						}
					</script>
					<script>
						function del(node) {
							$.ajax({
								type: "delete",
								url: 'con/visa/delete?' + 'visId=' + visId,
								//                dataType: "xml",				
								success: function (data) {
									$.messager.alert('消息', data.msg);
									$('#add').window('close');
									bindgrid();
								},
								error: function (XMLHttpRequest, textStatus, errorThrown) {
									$.messager.alert('消息', errorThrown);
								}
							});
						}

						function save() {
							if (!$('#fm').form('validate')) {
								return;
							}
							var model = {
								visId: $('#visId').textbox('getValue'),
								visCode: $('#visCode').textbox('getValue'),
								visName: $('#visName').textbox('getValue'),
								visConName: $('#visConName').textbox('getValue'),
								visConDate: $('#visConDate').textbox('getValue'),
								visDockId: $('#visDockId').textbox('getValue'),
								visDockName: $('#visDockName').textbox('getValue'),
								visDockHi: $('#visDockHi').textbox('getValue'),
								visDetail: $('#visDetail').textbox('getValue'),
								visFactoryCode: $('#visFactoryCode').textbox('getValue'),
								visFactoryName: $('#visFactoryName').textbox('getValue'),
								oaStatus: $('#oaStatus').textbox('getValue'),
								oaFlowId: $('#oaFlowId').textbox('getValue'),
								createTime: $('#createTime').textbox('getValue'),
								createName: $('#createName').textbox('getValue'),
								createId: $('#createId').textbox('getValue'),
								updateId: $('#updateId').textbox('getValue'),
								updateName: $('#updateName').textbox('getValue'),
								updateTime: $('#updateTime').textbox('getValue'),
								delFlag: $('#delFlag').textbox('getValue'),
								status: $('#status').textbox('getValue'),
								deptId: $('#deptId').textbox('getValue'),
								deptName: $('#deptName').textbox('getValue'),
								remark: $('#remark').textbox('getValue')
							};
							$.ajax({
								type: "post",
								dataType: "json",
								url: 'con/visa/save',
								data: JSON.stringify(model),
								contentType: "application/json",
								success: function (data) {
									if (data.code != 60200) {
										$.messager.alert('消息', data.msg);
									} else {
										$.messager.alert('消息', data.msg);
										let dg = $('#dg');
										dg.datagrid('enableFilter');
										dg.datagrid('load');
										$('#add').window('close');
									}
								},
								error: function (XMLHttpRequest, textStatus, errorThrown) {
									$.messager.alert('消息', errorThrown);
								}
							})

						}

						function editrow(row) {
							//编辑用户 
							if (row) {
								$('#add').window('open');
								$('#fm').form('load', row);
								getFileList(row.visId);
								$('#tabs').tabs('select', 0)
							} else {
								$.messager.alert('消息', '请选中一条数据');
							}
						}
					</script>
					<script>
						/**
						 *  按条件查询报价列表
						 */
						function selectList() {
							var startTime = $('#startTime').datebox('getValue')
							var endTime = $('#endTime').datebox('getValue')
							var status = $('#status').combobox('getValue');
							var dg = $('#dg');
							dg.datagrid('enableFilter');
							dg.datagrid('load', {
								startTime: startTime ? startTime : '',
								endTime: endTime ? endTime : '',
								status: status ? status : ''
							});
						}

						function bindgrid() {
							var startTime = $('#startTime').datebox('getValue')
							var endTime = $('#endTime').datebox('getValue')
							var status = $('#status').combobox('getValue');
							$('#dg').datagrid({
								title: '',
								queryParams: {
									startTime: startTime,
									endTime: endTime,
									status: status
								},
								url: "con/visa/selectList",
								iconCls: 'icon-application',
								width: getWidth(0.98),
								height: 400,
								nowrap: true,
								filterDelay: 0,
								rownumbers: true,
								animate: false,
								collapsible: false,
								clientPaging: false,
								remoteFilter: true,
								singleSelect: true,
								pagination: true,
								remoteSort: true,
								frozenColumns: [[{
									field: 'visId',
									title: '签证id',
									sortable: true,
									hidden: true,
									formatter: function (val, rec) {
										return val ? unescape(val) : '';
									}
								}, {
									field: 'visCode',
									title: '签证编码',
									sortable: true,
									width: 120,
									formatter: function (val, rec) {
										return val ? unescape(val) : '';
									}
								}, {
									field: 'visName',
									title: '签证名称',
									sortable: true,
									width: 280,
									formatter: function (val, rec) {
										return '<span title="' + val + '">' + val + '</span>';
									}
								},]],
								columns: [[{
									field: 'visConName',
									title: '施工单位',
									sortable: true,
									formatter: function (val, rec) {
										return val ? unescape(val) : '';
									}
								}, {
									field: 'visConDate',
									title: '施工日期',
									sortable: true,
									formatter: function (val, rec) {
										return val ? unescape(val) : '';
									}
									// }, {
									// 	field: 'visDockId',
									// 	title: '对接人id',
									// 	sortable: true,
									// 	hidden: true,
									// 	formatter: function (val, rec) {
									// 		return val ? unescape(val) : '';
									// 	}
								}, {
									field: 'visDockName',
									title: '对接人姓名',
									sortable: true,
									formatter: function (val, rec) {
										return val ? unescape(val) : '';
									}
								}, {
									field: 'visDockHi',
									title: '对接人HI',
									sortable: true,
									formatter: function (val, rec) {
										return val ? unescape(val) : '';
									}
								}, {
									field: 'visFactoryCode',
									title: '属地公司代码',
									sortable: true,
									formatter: function (val, rec) {
										return val ? unescape(val) : '';
									}
								}, {
									field: 'visFactoryName',
									title: '属地公司名称',
									sortable: true,
									formatter: function (val, rec) {
										return val ? unescape(val) : '';
									}
									// }, {
									// 	field: 'oaStatus',
									// 	title: 'oa状态',
									// 	sortable: true,
									// 	formatter: function (val, rec) {
									// 		return val ? unescape(val) : '';
									// 	}
								}, {
									field: 'createTime',
									title: '创建时间',
									sortable: true,
									formatter: function (val, rec) {
										return val ? unescape(val) : '';
									}
								}, {
									field: 'createName',
									title: '创建人姓名',
									sortable: true,
									formatter: function (val, rec) {
										return val ? unescape(val) : '';
									}
									// }, {
									// 	field: 'createId',
									// 	title: '创建人',
									// 	sortable: true,
									// 	hidden: true,
									// 	formatter: function (val, rec) {
									// 		return val ? unescape(val) : '';
									// 	}
									// }, {
									// 	field: 'updateId',
									// 	title: '修改人',
									// 	sortable: true,
									// 	hidden: true,
									// 	formatter: function (val, rec) {
									// 		return val ? unescape(val) : '';
									// 	}
								}, {
									field: 'updateName',
									title: '修改人姓名',
									sortable: true,
									formatter: function (val, rec) {
										return val ? unescape(val) : '';
									}
								}, {
									field: 'updateTime',
									title: '修改时间',
									sortable: true,
									formatter: function (val, rec) {
										return val ? unescape(val) : '';
									}
									// }, {
									// 	field: 'delFlag',
									// 	title: '是否删除',
									// 	sortable: true,
									// 	formatter: function (val, rec) {
									// 		return val ? unescape(val) : '';
									// 	}
								}, {
									field: 'visDetail',
									title: '描述',
									width: 210,
									sortable: true,
									formatter: function (val, rec) {
										var name = '';
										if (val) {
											name = '<span title="' + val + '">' + val + '</span>';
										} else {
											name = '';
										}
										return name;
									}
								}, {
									field: 'visProxy',
									title: '现场代表',
									sortable: true,
									formatter: function (val, rec) {
										return val ? unescape(val) : '';
									}
								}, {
									field: 'visDeptCharge',
									title: '部门负责人',
									sortable: true,
									formatter: function (val, rec) {
										return val ? unescape(val) : '';
									}
								}, {
									field: 'visLeader',
									title: '分管领导',
									sortable: true,
									formatter: function (val, rec) {
										return val ? unescape(val) : '';
									}
								}, {
									field: 'visAudit',
									title: '审计部',
									sortable: true,
									formatter: function (val, rec) {
										return val ? unescape(val) : '';
									}
								}, {
									field: 'oaFlowId',
									title: 'oa编号',
									sortable: true,
									formatter: function (val, rec) {
										return val ? unescape(val) : '';
									}
								}, {
									field: 'status',
									title: '状态',
									sortable: true,
									formatter: function (val, rec) {
										return val ? unescape(val) : '';
									}
									// }, {
									// 	field: 'deptId',
									// 	title: '所属部门',
									// 	sortable: true,
									// 	hidden: true,
									// 	formatter: function (val, rec) {
									// 		return val ? unescape(val) : '';
									// 	}
								}, {
									field: 'deptName',
									title: '所属部门名称',
									sortable: true,
									formatter: function (val, rec) {
										return val ? unescape(val) : '';
									}
								}, {
									field: 'remark',
									title: '备注',
									sortable: true,
									formatter: function (val, rec) {
										return val ? unescape(val) : '';
									}
								}]],
								// toolbar: [{
								// 	text: '增加',
								// 	iconCls: 'icon-add',
								// 	handler: function () {
								// 		$('#fm').form('clear');
								// 		$('#add').window('open');
								// 	}
								// }, '-', {
								// 	text: '编辑',
								// 	iconCls: 'icon-edit',
								// 	handler: function () {
								// 		editrow()
								// 	}
								// }, '-', {
								// 	text: '删除',
								// 	iconCls: 'icon-cancel',
								// 	handler: function () {
								// 		var row = $('#dg').datagrid('getSelected');
								// 		if (row) {
								// 			$.messager.confirm('提示', '确定要删除这个吗?', function (r) {
								// 				if (r) {
								// 					del(row);
								// 				}
								// 			});
								// 		}
								// 	}
								// }],
								onLoadSuccess: function () {
								},
								onDblClickRow: function () {
									var row = $('#dg').datagrid('getSelected');
									editrow(row);
								}
							});
							$('#dg').datagrid('enableFilter');
						}

						// 导出为Excel
						function exportList() {
							let startTime = $('#startTime').datebox('getValue')
							let endTime = $('#endTime').datebox('getValue')
							let status = $('#status').combobox('getValue')
							var form = [];
							form.push('startTime=' + (startTime ? startTime : ''));
							form.push('endTime=' + (endTime ? endTime : ''));
							form.push('status=' + (status ? status : ''));
							let url = "api/con/visa/export"
							let xhr = new XMLHttpRequest()
							xhr.open('POST', url, true)
							xhr.setRequestHeader('Content-Type',
								'application/x-www-form-urlencoded');
							xhr.setRequestHeader('token', localStorage.getItem('token'));
							xhr.setRequestHeader('userType', localStorage.getItem('userType'));
							xhr.responseType = 'blob'
							xhr.onload = function () {
								if (this.status == 200) {
									let blob = this.response
									let reader = new FileReader()
									reader.readAsDataURL(blob)
									reader.onload = function (e) {
										let a = document.createElement('a')
										a.download = '工程签证' + new Date().toLocaleDateString() + '-' + new Date().toLocaleTimeString() + '.xlsx'
										a.href = e.target.result
										$('body').append(a)
										a.click()
										$(a).remove()
									}
								}
							}
							xhr.send(form.join('&'))
						}
					</script>
					<style scoped="scoped">
						.textbox {
							height: 20px;
							margin: 0;
							padding: 0 2px;
							box-sizing: content-box;
						}

						/*.table tr {
        height: 15px;
    }*/
					</style>
					<div class="query_criteria" id="query_criteria">
						<div style="margin: 5px 0px">
							<%-- 搜索框 --%>
								<label style="font-size: 12px;">创建时间：</label> <input class="easyui-datebox"
									name="startTime" id="startTime"
									data-options="required:true,showSeconds:false,formatter:myformatter,parser:myparser"
									value="" style="width: 150px"> <label style="font-size: 10px;">~</label> <input
									class="easyui-datebox" name="endTime" id="endTime"
									data-options="required:true,showSeconds:false,formatter:myformatter,parser:myparser"
									style="width: 150px" /> <label
									style="margin-left: 20px; font-size: 12px;">状态：</label> <input
									class="easyui-combobox" id="status" name="status" style="width: 80px;" data-options="valueField: 'value',editable:false,
						textField: 'label',panelHeight:'auto',data: [{
							label: '全部',
							value: ''
						},{
							label: '待提交',
							value: '0',
							selected:true
						},{
							label: '已提交',
							value: '1'
						},{
							label: '已打印',
							value: '2'
						}]">
								</select> <a id="search" style="margin-left: 30px" href="javascript:void(0)"
									class="easyui-linkbutton" data-options="iconCls:'icon-search'"
									onclick="selectList()">查询</a> <a id="export" href="javascript:void(0)"
									class="easyui-linkbutton" data-options="iconCls:'icon-export'"
									onclick="exportList()">导出</a>
						</div>

						<table id="dg"></table>


						<div id="add" class="easyui-window" closed="true" modal="true" title="签证信息"
							style="width: 700px; height: 400px; padding: 5px 5px">
							<div id="tabs" class="easyui-tabs" style="width: 650px; height: 350px">
								<div title="基本信息" style="padding: 5px;">
									<form id="fm" class="ssec-form">
										<table class="table">
											<tr>
												<td>
													<div class="ssec-label">签证编码：</div>
												</td>
												<td>
													<div class="ssec-text normal">
														<input id="visCode" name="visCode" class="easyui-textbox"
															data-options="disabled:true" style="width: 200px" /><input
															id="visId" name="visId" type="hidden" /><input id="oaFlowId"
															name="oaFlowId" type="hidden" />
													</div>
												</td>
												<td>
													<div class="ssec-label">签证名称：</div>
												</td>
												<td>
													<div class="ssec-text normal">
														<input id="visName" name="visName" class="easyui-textbox"
															data-options="required:true" style="width: 200px" />
													</div>
												</td>
											</tr>
											<tr>
											</tr>
											<tr>
												<!-- <td>
													<div class="ssec-label">施工单位：</div>
												</td>
												<td>
													<div class="ssec-text normal">
														<input id="visConName" name="visConName" class="easyui-textbox"
															data-options="required:true" style="width: 200px" />
													</div>
												</td> -->
												<td>
													<div class="ssec-label">完工日期：</div>
												</td>
												<td>
													<div class="ssec-text normal">
														<input class="easyui-datebox" name="visConDate" id="visConDate"
															data-options="required:true,showSeconds:false,formatter:myformatter,parser:myparser,editable:false"
															value="" style="width: 200px">
													</div>
												</td>
												<td>
													<div class="ssec-label">审核人：</div>
												</td>
												<td>
													<div class="ssec-text normal"> <input class="easyui-combobox"
															id="visDockHi" name="visDockHi" style="width: 60%;"
															data-options="required:true,valueField: 'value',editable:false,
			textField: 'label',panelHeight:'auto', url: 'sysDict/queryItemByTypeName?dicName=新源签证',
			method: 'get',
			valueField: 'dicValue',
			textField: 'dicName'" />
													</div>
												</td>
											</tr>
											<tr>
											</tr>
											<tr>
											</tr>
											<tr>
												<td>
													<div class="ssec-label">描述：</div>
												</td>
												<td colspan="3">
													<table>
														<tr>
															<td>
																<div class="ssec-text normal">
																	<input id="visDetail" name="visDetail"
																		class="easyui-textbox"
																		style="width: 500px;height: 230px"
																		data-options="required:true,readonly:false,multiline:true">
																</div>
															</td>
														</tr>
													</table>
												</td>

											</tr>
											<!-- <tr>
										<td>
											<div class="ssec-label">属地公司代码：</div>
										</td>
										<td>
											<div class="ssec-text normal">
												<input id="visFactoryCode" name="visFactoryCode" class="easyui-textbox"
													data-options="required:true" />
											</div>
										</td>
									</tr> -->
											<!-- <tr>
										<td>
											<div class="ssec-label">属地公司名称：</div>
										</td>
										<td>
											<div class="ssec-text normal">
												<input id="visFactoryName" name="visFactoryName" class="easyui-textbox"
													data-options="required:true" />
											</div>
										</td>
									</tr>
									<tr>
										<td>
											<div class="ssec-label">所属部门：</div>
										</td>
										<td>
											<div class="ssec-text normal">
												<input id="deptId" name="deptId" class="easyui-textbox"
													data-options="required:true" />
											</div>
										</td>
									</tr> -->
											<!-- <tr>
										<td>
											<div class="ssec-label">所属部门名称：</div>
										</td>
										<td>
											<div class="ssec-text normal">
												<input id="deptName" name="deptName" class="easyui-textbox"
													data-options="required:true" />
											</div>
										</td>
									</tr> -->
											<!-- <tr>
										<td>
											<div class="ssec-label">备注：</div>
										</td>
										<td>
											<div class="ssec-text normal">
												<input id="remark" name="remark" class="easyui-textbox"
													data-options="required:true" />
											</div>
										</td>
									</tr> -->
										</table>
										<!-- <div style="padding: 5px; text-align: right;">
									<a class="easyui-linkbutton" onclick="save();" iconcls="icon-save">保存</a>
								</div> -->
									</form>
								</div>
								<div title="附件" style="padding: 5px;">
									<table>
										<tr>
											<td colspan="3"><input type="button" id="uploadbtn" value="选择文件..." />
												<input type="file" id="uploadpicker" accept="" onchange="changeFile()"
													multiple style="display: none;" />
												<span>（文件名称不能包含斜杠、空格、&、#等特殊字符）</span>
											</td>
										</tr>
										<tr>
											<td><label style="width: 40%; text-align: right;">附件下载：</label>
												<ul id="checkfileList"></ul>
											</td>
										</tr>
									</table>
								</div>
							</div>
						</div>
					</div>
		</body>

		</html>